package com.jumi.microservice.stock.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jumi.microservice.stock.domain.*;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description
 * @ClassName StockTransferMapper
 * @Author Abel Yang
 * @Date 2020/9/11/011 13:00
 **/
public interface StockTransferMapper extends BaseMapper<StockTransferDO> {
    /**
     * @Description: 查询调货记录
     * @Param stockTransferRequestDTO
     * @Return {@link List<    StockTransferVO   >}
     * @Throws
     * @Author Abel Yang
     * @Date 2020/9/11/011 14:10
     */
    @Select("<script>select s.id,s.warehouse_id,s.to_warehouse_id,s.goods_id,\n" +
            " g.goods_code,g.goods_name,g.goods_type,g.supplier_id,g.unit_id,\n" +
            " s.total_transfer_num,s.transfer_remark,s.transfer_time,from_unixtime(s.transfer_time) as transfer_time_str," +
            " s.check_status,s.check_name,s.check_time,\n" +
            " s.check_remark,s.create_by,s.create_time\n" +
            " from jm_stock_transfer as s\n" +
            " left join jm_goods as g on s.goods_id=g.goods_id " +
            " WHERE s.is_del=0 " +
            "<if test=\"warehouseId!= null and warehouseId!=0\"> and s.warehouse_id=#{warehouseId}</if>" +
            "<if test=\"toWarehouseId!= null and toWarehouseId!=0\"> and s.to_warehouse_id=#{toWarehouseId}</if>" +
            "<if test=\"goodsName!= null and goodsName!=''\"> and g.goods_name like concat(#{goodsName},'%')</if>" +
            "<if test=\"goodsType!= null\"> and g.goods_type=#{goodsType}</if>" +
            "<if test=\"checkStatus!= null\"> and s.check_status=#{checkStatus}</if>" +
            "<if test=\"searchType != null\">" +
                "<choose>" +
                    "<when test=\"searchType==0\">" +
                        "<if test=\"startTime != null and startTime!='' \"> and s.transfer_time <![CDATA[ >= ]]> UNIX_TIMESTAMP(#{startTime})</if>" +
                        "<if test=\"endTime != null and endTime!='' \"> and s.transfer_time <![CDATA[ < ]]> UNIX_TIMESTAMP(#{endTime})</if>" +
                    "</when>" +
                    "<otherwise>" +
                        "<if test=\"startTime != null and startTime!='' \"> and s.check_time <![CDATA[ >= ]]> UNIX_TIMESTAMP(#{startTime})</if>" +
                        "<if test=\"endTime != null and endTime!='' \"> and s.check_time <![CDATA[ < ]]> UNIX_TIMESTAMP(#{endTime})</if>" +
                    "</otherwise>"+
                "</choose>" +
            "</if>" +
            "ORDER BY s.id desc" +
            "</script>")
    List<StockTransferVO> getTransferList(StockTransferSearchDTO stockTransferSearchDTO);

    @Select("<script>" +
            "select s.id,s.warehouse_id,s.to_warehouse_id,s.goods_id,s.transfer_remark,s.check_remark,from_unixtime(s.transfer_time) as transfer_time_str," +
            " s.check_status, g.goods_name,g.supplier_id,g.unit_id" +
            " from jm_stock_transfer as s join jm_goods as g on s.goods_id=g.goods_id" +
            " where s.id = #{id} and s.is_del = 0" +
            "</script>")
    StockTransferDetailVO getTransferGoodsById(Long id);
}
